home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xmeasure
/
runtests.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
12KB
|
432 lines
/*==================================================================
* File : runtests.c
* Package: Xmeasure
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
* All rights granted to University of Illinois Board of Regents.
*==================================================================*/
/*
* int RunTests (XD *xd)
* int Calibrate(XD *xd, TestRequest *test, GC gc, SizePair *sizepair)
* InitGCarray (XD *xd)
* PrintGfxvals(FILE *fp, int gxmode, int linestyle, int fillstyle,
* int linewidth)
*/
#include "perf.h"
int debuglevel=1;
/*
int debuglevel = 0;
int debuglevel = 2;
*/
static float testtime = 1.0; /* Each test is run for 1.0 seconds */
static float calibratetime = 1.0; /* Run calibration steps for 1.0 secs */
static int repeats = 3 ; /* Number of times to repeat each test */
static int calibrate_reps= 6;
extern TestRequest testrequest[];
extern char *FontName[];
extern unsigned NUMFONTS;
SetTesttime(time)
float time;
{ testtime = time; }
SetRepeats(reps)
int reps;
{
int tmp;
repeats = reps;
tmp = 2 * reps;
if (tmp > calibrate_reps)
calibrate_reps = 6;
}
RunTests(xd)
XD *xd;
{
int i, j, count;
double *timespent; /* Array of dimension "repeats" */
TestRequest *testptr;
char message[128];
XParams xp; /* Parameters to pass to computations */
/*
* Allocate the "timespent" array
*/
timespent = (double *) calloc((unsigned) repeats, sizeof(double));
/*
* Main loop.
*/
for (i = 0; i < MAXREQUESTS; i++) { /* For each request */
testptr = &testrequest[i]; /* Init. testptr for this request */
if (testptr->dothis != TRUE)
continue; /* Skip this iteration */
XDestroySubwindows(xd->display, xd->window);
XClearWindow(xd->display, xd->window); /* Clear the display surface */
/*
* Do the computation for each size pair of this request
*/
for (j=0; j< MAXSIZEPAIRS; j++){/* For each size pair of this request */
if (testptr->sizepair[j].s1 == INVALID)
break; /* First invalid pair causes termination */
xp.sizepair = &testptr->sizepair[j];
/* The following are set in the init function from the knowledge of
the size pair, and the number of objects to process in one call. */
xp.size = 0; /* default value of size is zero */
xp.numobjs = 1; /* default number of objects to process in
one call is one */
switch(testptr->msgclass) {
case WIN:
xp.gc = xd->gc;
Calibrate(xd, testptr, &xp); /* Set xp.itns */
if (xp.itns == 0) /* Error flag */
break;
printf("# %s ", testptr->name);
if (debuglevel > 0) fflush(stdout);
for (count = 0; count < repeats; count++) {
sprintf(message,
"Testing Xlib %s function: %s. Test %d of %d",
( testptr->msgclass == WIN) ? "windowing":
((testptr->msgclass == TXT) ? "text" : "graphics"),
testptr->name, count+1, repeats);
printmessage(xd, message);
testptr->init(xd, &xp);
Synchronize(xd);
InitTimer();
testptr->func(xd, &xp);
Synchronize(xd);
timespent[count] = TimeSpent();
testptr->cleanup(xd, &xp);
printf("(%d,%6.3lf) ",xp.size,
(double) (xp.itns * xp.numobjs) /timespent[count]);
if (debuglevel > 0) fflush(stdout);
}
printf("\n%s (%d,%6.3lf) ", testptr->name, xp.size,
(double) (xp.itns * xp.numobjs)/median(timespent,repeats));
printf("\n");
if (debuglevel > 0) fflush(stdout);
break;
case GFX: {
int gxmode=0, linestyle=0, fillstyle=0, linewidth=0;
int gfxslot;
/*
* Now run the tests for each of the graphics type functions
*/
for (linewidth=0; linewidth < NUMLINEWIDTHS; linewidth++)
for (fillstyle=0; fillstyle < NUMFILLSTYLES; fillstyle++)
for (linestyle=0; linestyle < NUMLINESTYLES; linestyle++)
for (gxmode =0; gxmode < NUMGXMODES; gxmode++)
{
gfxslot = GFXINDEX(gxmode, linestyle, fillstyle, linewidth);
if (debuglevel > 1) {
printf("\ngfxslot = %d\n", gfxslot);
}
if (debuglevel > 0) fflush(stdout);
XClearWindow(xd->display, xd->window);
xp.gc = xd->gcarray[gfxslot];
Calibrate(xd, testptr, &xp);
if (xp.itns == 0) /* Error flag */
break;
printf("# %s ", testptr->name);
for (count = 0; count < repeats; count++) {
sprintf(message,
"Testing Xlib %s function: %s. Test %d of %d",
( testptr->msgclass == WIN) ? "windowing":
((testptr->msgclass == TXT) ? "text" : "graphics"),
testptr->name, count+1, repeats);
printmessage(xd, message);
XClearWindow(xd->display, xd->window);
/* Initialize done outside these two loops */
testptr->init(xd, &xp);
Synchronize(xd);
InitTimer();
testptr->func (xd, &xp);
Synchronize(xd);
testptr->cleanup(xd, &xp);
timespent[count] = TimeSpent();
/* Cleanup done outside these two loops */
printf("(%d, %6.3lf) ",xp.size,
(double) (xp.itns * xp.numobjs) /timespent[count]);
if (debuglevel > 0) fflush(stdout);
}
printf("\n");
printf("%-20s ", testptr->name);
PrintGfxvals(stdout, gxmode, linestyle, fillstyle,
linewidth);
printf(" (%d,%6.3lf) ", xp.size,
(double)(xp.itns*xp.numobjs)/median(timespent,repeats));
printf("\n");
if (debuglevel > 0) fflush(stdout);
}
break;
}
case TXT: {
int txtslot=0;
/*
* Now run the tests for each of the fonts
*/
for (txtslot=0; txtslot < NUMFONTS; txtslot++) {
if (FontName[txtslot] == NULL)
break;
if (debuglevel > 1) {
printf("\ntxtslot = %d\n", txtslot);
}
if (debuglevel > 0) fflush(stdout);
XClearWindow(xd->display, xd->window);
xp.sizepair->s2=txtslot; /* Which font is this ? */
xp.gc = xd->gc;
Calibrate(xd, testptr, &xp);
if (xp.itns == 0) /* Error flag */
break;
printf("# %s ", testptr->name);
for (count = 0; count < repeats; count++) {
sprintf(message,
"Testing Xlib %s function: %s. Test %d of %d",
( testptr->msgclass == WIN) ? "windowing":
((testptr->msgclass == TXT) ? "text" : "graphics"),
testptr->name, count+1, repeats);
printmessage(xd, message);
XClearWindow(xd->display, xd->window);
/* Initialize done outside these two loops */
testptr->init(xd, &xp);
Synchronize(xd);
InitTimer();
testptr->func (xd, &xp);
Synchronize(xd);
testptr->cleanup(xd, &xp);
timespent[count] = TimeSpent();
/* Cleanup done outside these two loops */
printf("(%d, %6.3lf) ",xp.size,
(double) (xp.itns * xp.numobjs) /timespent[count]);
if (debuglevel > 0) fflush(stdout);
}
printf("\n");
printf("%-12s ", testptr->name);
printf("fontname=%s", FontName[txtslot]);
printf(" (%d,%6.3lf) ", xp.size,
(double)(xp.itns*xp.numobjs)/median(timespent,repeats));
printf("\n");
if (debuglevel > 0) fflush(stdout);
}
break;
}
default:
break;
} /* switch(testptr->msgclass) */
} /* for (j=0; j < MAXSIZEPAIRS ... ) */
} /* for (i=0; i < MAXREQUESTS ... ) */
}
#define MAXSCALE 10.0
#define MINSCALE (1.0 / MAXSCALE)
Calibrate(xd, test, xp)
XD *xd;
TestRequest *test;
XParams *xp;
{
double timespent;
double scale = 0.0;
long low=1, high=MAXLONG;
double tlow=0.0, thigh=MAXDOUBLE;
long saveitns;
int i;
char message[128];
sprintf(message, "Calibrating Xlib %s function: %s.",
( test->msgclass == WIN) ? "windowing":
((test->msgclass == TXT) ? "text" : "graphics"),
test->name);
printmessage(xd, message);
xp->itns = 1; /* Initially run only one test */
if (debuglevel > 1)
printf("Calibrating Request %d: %s\n", test->number, test->name);
for (i =0; i < calibrate_reps; i++) {/* Estimate no. of iterations needed */
if (debuglevel > 1) {
printf("high = %10ld, low = %5ld ",high, low);
printf("itns = %5ld ", xp->itns); fflush(stdout);
}
test->init(xd, xp);
if (xp->itns == 0) {/* An error has occured */
printf("# Calibrate: Cannot calibrate %s\n", test->name);
test->cleanup(xd, xp);
return;
}
Synchronize(xd);
InitTimer();
test->func(xd, xp);
Synchronize(xd);
timespent = TimeSpent();
test->cleanup(xd, xp);
if (timespent < .01) /* Clock grain 10 ms */
timespent = .01;
if (debuglevel > 1){
printf("timespent = %6.4lf\n", timespent);
fflush(stdout);
}
saveitns = xp->itns;
scale = calibratetime / timespent; /* How much to scale ? */
if ((scale > 0.9 ) && (scale < 2.0))
break; /* These many iterations are enough */
if (scale > MAXSCALE) scale = MAXSCALE;
else if (scale < MINSCALE) scale = MINSCALE;
/* Now compute the new figure of itns */
/*
xp->itns = (long) (xp->itns * scale);
*/
/* Set new high and low watermarks */
if (scale < 1.0) { /* We overshot */
if (high > saveitns) {
high = saveitns;
thigh = timespent;
}
}
else { /* We undershot */
if (low < saveitns) {
low = saveitns;
tlow = timespent;
}
}
/* Now compute the new figure for iterations */
if (high != MAXLONG) { /* Don't bother if it is still initial value */
if (xp->itns > low)
xp->itns = (long) (low + ((high - low) * (calibratetime - tlow) /
(thigh - tlow) ));
}
else xp->itns = (long) (xp->itns * scale);
if (xp->itns == 0)
xp->itns = 1;
if (xp->itns == 1)
break;
}
/* Normalize the number of iterations needed to go upto "testtime" */
scale = testtime / timespent;
xp->itns = (long) (xp->itns * scale);
if (xp->itns == 0)
xp->itns = 1;
if (debuglevel > 1) {
printf("Final itns returned by Calibrate = %4ld\n", xp->itns);
fflush(stdout);
}
}
int LineWidths[] = { 0, 1, 3, 10};
/*
* Initialize the 32 graphics contexts to be used for graphics operations
*/
InitGCarray(xd)
XD *xd;
{
XGCValues values;
unsigned long valuemask=0;
int gxmode, linestyle, fillstyle, linewidth;
int gfxslot;
valuemask = GCFunction | GCLineStyle | GCFillStyle | GCLineWidth |
GCForeground | GCBackground;
values.foreground = xd->foreground;
values.background = xd->background;
for ( linewidth = 0; linewidth < NUMLINEWIDTHS; linewidth++)
for ( fillstyle = 0; fillstyle < NUMFILLSTYLES; fillstyle++)
for ( linestyle = 0; linestyle < NUMLINESTYLES; linestyle++)
for (gxmode = 0; gxmode < NUMGXMODES ; gxmode ++)
{
/*
* Set the mode for the Graphics function
*/
switch(gxmode) { /* Can have two values */
case 0: values.function = GXcopy;
break;
default: values.function = GXxor;
break;
}
/*
* Set the linestyle
*/
switch(linestyle) { /* Can have two values */
case 0: values.line_style = LineSolid;
break;
default: values.line_style = LineDoubleDash;
break;
}
/*
* Set the fillstyle
*/
switch(fillstyle) { /* Can have two values */
case 0: values.fill_style = FillSolid;
break;
default: values.fill_style = FillOpaqueStippled;
break;
}
/*
* Set line width
*/
values.line_width = LineWidths[linewidth];
/*
* Now initialize the graphics context
*/
gfxslot = GFXINDEX(gxmode, linestyle, fillstyle, linewidth);
xd->gcarray[gfxslot] = XCreateGC(xd->display, xd->window,
valuemask, &values);
}
}
#define BUFSIZE 128
PrintGfxvals(fp, gxmode, linestyle, fillstyle, linewidth)
FILE *fp;
int gxmode, linestyle, fillstyle, linewidth;
{
char buffer[BUFSIZE], tmp[BUFSIZE];
bzero (buffer, BUFSIZE);
/* Print the mode for the Graphics function */
switch(gxmode) { /* Can have two values */
case 0:
strcat(buffer, "gxmode=GXcopy ");
break;
default:
strcat(buffer, "gxmode=GXxor ");
break;
}
/* Print the linestyle */
switch(linestyle) { /* Can have two values */
case 0:
strcat(buffer, "linestyle=LineSolid ");
break;
default:
strcat(buffer, "linestyle=LineDoubleDash ");
break;
}
/* Print the fillstyle */
switch(fillstyle) { /* Can have two values */
case 0:
strcat(buffer, "fillstyle=FillSolid ");
break;
default:
strcat(buffer, "fillstyle=FillOpaqueStippled ");
break;
}
/* Print line width */
sprintf(tmp, "linewidth=%-2d", LineWidths[linewidth] );
strcat (buffer, tmp);
fprintf(fp, "%s", buffer);
}